package com.zjl.cms.service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjl.cms.base.model.Paging;
import com.zjl.cms.dao.BaseDao;
import com.zjl.cms.model.Feeds;
import com.zjl.cms.model.User;

@Service
public class FeedsService {
	
	@Autowired
	private BaseDao baseDao;
	
	public void findUserFeeds(Paging paging, String ownId) {
		
		//封装查询参数
		User u=new User();
		u.setId(ownId);
		paging.setParameter(u);
		
		List<Feeds> list = baseDao.select("com.zjl.cms.dao.FeedsMapper.selectByOwnid", paging);

		Set<Long> postIds = new HashSet<>();

		for (FeedsPO po : list) {
			Feeds f = BeanMapUtils.copy(po);
			rets.add(f);

			postIds.add(f.getPostId());
		}

		// 加载文章
		Map<Long, Post> postMap = postService.findMultileMapByIds(postIds);

		for (Feeds f : rets) {
			f.setPost(postMap.get(f.getPostId()));
		}
		paging.setResults(rets);
	}

}
